// Author: Ivan Kazmenko (gassa@mail.ru)
// Standard checker: compare sequences of tokens ignoring case
module check;
import std.algorithm;
import std.ascii;
import std.format;
import std.range;
import testlib;

immutable int tokensToReport = 10;

void main (string [] args)
{
	initTestlib !(TestlibRole.checker) (args);

	auto outTokens = outFile.byToken;
	auto ansTokens = ansFile.byToken;
	int tokenNumber = 0;
	string [] reportTokens;
	foreach (outToken, ansToken; zip (outTokens, ansTokens))
	{
		tokenNumber += 1;

		if (outToken.map !(toLower) != ansToken.map !(toLower))
		{
			quit (ExitCode.wa, "token ", tokenNumber, ": `",
			    outToken.shorten, "' instead of `",
			    ansToken.shorten, "'");
		}
		if (reportTokens.length < tokensToReport)
		{
			reportTokens ~= outToken.shorten;
		}
	}
	if (!outTokens.empty)
	{
		quit (ExitCode.pe, "extra tokens: more than ", tokenNumber);
	}
	if (!ansTokens.empty)
	{
		quit (ExitCode.pe, "not enough tokens: ", tokenNumber);
	}
	outFile.checkEof ();
	ansFile.checkEof ();
	auto message = format ("%s token%s: %(%s, %)%s",
	    tokenNumber, tokenNumber == 1 ? "" : "s", reportTokens,
	    tokenNumber > reportTokens.length ? "..." : "");
	quit (ExitCode.ok, message);
}
